package com.chuanyin.mp3player.widget;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuanyin.mp3player.R;
import com.chuanyin.mp3player.commons.Constants;
import com.chuanyin.mp3player.storage.Song;

public class SongsAdapter extends BaseAdapter{
	private LayoutInflater mLayoutInflater;
	private ArrayList<Song> songs ;
	private  int mDataType ;
	public SongsAdapter(Context ctx,ArrayList<Song> songs,int mDataType){
		mLayoutInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.songs = songs;
		this.mDataType = mDataType;
	}

	@Override
	public int getCount() {
		return songs.size();
	}

	@Override
	public Object getItem(int position) {
		return songs.get(position);
	}

	@Override
	public long getItemId(int id) {
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if(view == null){
			if(Constants.MP3_TYPE_ALL_SONGS == mDataType){
				view = mLayoutInflater.inflate(R.layout.all_songs_item, null);
				TextView titleTxt =(TextView)view.findViewById(R.id.titleTxt);
				TextView singerTxt = (TextView)view.findViewById(R.id.singerTxt);
				titleTxt.setText(songs.get(position).getTitle());
				singerTxt.setText(songs.get(position).getSinger());
			}else if(Constants.MP3_TYPE_LAST_PLAYED == mDataType){
				view = mLayoutInflater.inflate(R.layout.last_played_item, null);
				TextView lastPlayedTtitleTxt = (TextView)view.findViewById(R.id.lastPlayedTtitleTxt);
				lastPlayedTtitleTxt.setText(position+1+". "+songs.get(position).getTitle());
			}else if(Constants.MP3_TYPE_SINGER == mDataType){
				view = mLayoutInflater.inflate(R.layout.singer_item, null);
				TextView singerNameTxt = (TextView)view.findViewById(R.id.singerNameTxt);
				TextView songCountTxt = (TextView)view.findViewById(R.id.songCountTxt);
				singerNameTxt.setText(songs.get(position).getSinger());
				songCountTxt.setText(songs.get(position).getCount()+" songs");
			}else if(Constants.MP3_TYPE_BAIDU_MUSIC == mDataType){
				view = mLayoutInflater.inflate(R.layout.online_music_item, null);
				TextView titleTxt =(TextView)view.findViewById(R.id.titleTxt);
				titleTxt.setText(songs.get(position).getTitle());
			}
		}
		return view;
	}
	
}

